<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>优惠卷</title>
    <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
    <script src="../utils/flexible.js"></script>
    <link rel="stylesheet" href="../css/coupon.css">

</head>
<body>
    <!-- 头部 -->
    <header>
        <button>返回</button>
        <p>优惠卷</p>
        <img src="../images/header_app.png" alt="">
    </header>

    <!-- 优惠卷列表 -->
    <ul class="ulall">

    </ul>
   


    <!-- 底部 -->
    <footer>
        <ul>
            <li>登录</li>
            <li>注册</li>
            <li class="returntop">返回顶部</li>
        </ul>
        <p>
            手机APP下载慢慢买手机版-掌上比价平台<br>
            m.manmanbuy.com
        </p>
    </footer>
</body>
</html>

<script>
    // 返回上一级
    let bn=document.querySelector('button');
    bn.addEventListener('click',function(){
        history.go(-1);
    })

    // 优惠卷主页函数
    function render1(data=[]){
        let html=''
        data.forEach(item=>{
            html+=`
                <li couponid=${item.couponId} couponlink=${item.couponLink} >
                    ${item.couponTitle}
                </li>
                
            `
        })
        $('.ulall').html(html)

    }




    // 获取优惠卷主页数据
    $.ajax({
        url:'http://chst.vip:1234/api/getcoupon'
    })
    .then(res=>{
        console.log(res);
        render1(res.result);
        $('.ulall').on('click','li',function(){
            let couponid=$(this).attr('couponid')
            let couponlink=$(this).attr('couponLink')
            location.href=`../html/couponproduct.html?couponid=${couponid}`
            console.log(couponid,couponlink);
        })
    })





    // 返回顶部
    $('footer .returntop').click(function(e){
        document.documentElement.scrollTop=0;
        console.log(456);
    })
</script>